﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace TavDom.Library.Core.Utilities.EnumUtilities
{
    public class EnumUtilities
    {
        public static List<EnumItem> GetEnumList(Type enumType)
        {
            var enumValues = Enum.GetValues(enumType);
            return (
                from object value in enumValues
                let attribute = (EnumTextAttribute)enumType.GetMember(value.ToString())[0].GetCustomAttributes(typeof(EnumTextAttribute), false).FirstOrDefault()
                let text = attribute != null ? attribute.Text : value.ToString()
                select new EnumItem
            {
                Text = text,
                Value = value.GetHashCode()
            }).ToList();
        }
    }
}
